﻿//var jcarousel_framewidth, jcarousel_frameheight, jcarousel_picwidth, jcarousel_picheight, jcarousel_bid, jcarousel_delaytime;
//document.writeln("<link href=\"/plugins/jcarousel/style.css\" rel=\"stylesheet\" type=\"text/css\" />");
document.writeln("<link href=\"/plugins/jcarousel/skins/ie7/skin.css\" rel=\"stylesheet\" type=\"text/css\" />");
document.writeln("<style type=\"text/css\">");
document.writeln(".jcarousel-skin-ie7 .jcarousel-container-horizontal { width: " + jcarousel_framewidth + "px; padding: 20px 40px; }");
document.writeln(".jcarousel-skin-ie7 .jcarousel-clip-horizontal { width: " + jcarousel_framewidth + "px; height: " + jcarousel_frameheight + "px; }");
document.writeln(".jcarousel-skin-ie7 .jcarousel-item { width: " + jcarousel_picwidth + "px; height: " + jcarousel_picheight + "px; border: 1px solid #fff; }");
document.writeln(".jcarousel-skin-ie7 .jcarousel-next-horizontal { position: absolute; top: " + ( jcarousel_picheight/4+43) + "px; right: 5px; width: 32px; height: 32px; cursor: pointer; }");
document.writeln(".jcarousel-skin-ie7 .jcarousel-prev-horizontal { position: absolute; top: " + ( jcarousel_picheight/4+43)+ "px; left: 5px; width: 32px; height: 32px; cursor: pointer; }");
document.writeln("</style>");
document.writeln("<div id=\"mycarousel\" class=\"jcarousel-skin-ie7\">");
document.writeln("<ul></ul>");
document.writeln("</div>");

var scripts = [
"/js/jquery-1.4.4.min.js",
"/plugins/jcarousel/js/jquery.jcarousel.min.js"
];
seriesLoadScripts(scripts, function()
{
    function mycarousel_itemLoadCallback(carousel, state)
    {
        // Since we get all URLs in one file, we simply add all items
        // at once and set the size accordingly.
        if (state != 'init')
            return;

        jQuery.get('/plugins/jcarousel/getscrolldata.ashx?bid=' + jcarousel_bid, function(data)
        {
            var dd = eval(data);
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, dd);
        });
    };

    function mycarousel_itemAddCallback(carousel, first, last, data)
    {
        // Simply add all items at once and set the size accordingly.
        // var items = data.split('|');

        for (i = 0; i < data.length; i++)
        {
            var items = data;
            carousel.add(i + 1, mycarousel_getItemHTML(items[i].id, items[i].picurl));
        }
        carousel.size(items.length);
    };

    /**
    * Item html creation helper.
    */
    function mycarousel_getItemHTML(id, url)
    {
        return '<a href=\"/?fn=detail&id=' + id + '\" target=_blank ><img src="' + url + '"  alt="" /></a>';
    };

    jQuery(document).ready(function()
    {
        jQuery('#mycarousel').jcarousel(
        {
            auto: jcarousel_delaytime,
            itemLoadCallback: mycarousel_itemLoadCallback
        });
    });
});



function seriesLoadScripts(scripts, callback)
{
    if (typeof (scripts) != "object") var scripts = [scripts];
    var HEAD = document.getElementsByTagName("head").item(0) || document.documentElement;
    var s = new Array(), last = scripts.length - 1, recursiveLoad = function(i)
    { //递归
        s[i] = document.createElement("script");
        s[i].setAttribute("type", "text/javascript");
        s[i].onload = s[i].onreadystatechange = function()
        { //Attach handlers for all browsers
            if (!/*@cc_on!@*/0 || this.readyState == "loaded" || this.readyState == "complete")
            {
                this.onload = this.onreadystatechange = null; this.parentNode.removeChild(this);

                if (i != last) recursiveLoad(i + 1); else if (typeof (callback) == "function") callback();
            }
        }
        s[i].setAttribute("src", scripts[i]);
        HEAD.appendChild(s[i]);
    };
    recursiveLoad(0);
}
